/**
 * @param {string} allowed
 * @param {string[]} words
 * @return {number}
 */
var countConsistentStrings = function (allowed, words) {
  return words.filter(item => {
    let flag = true
    let index = 0
    const len = item.length
    while (flag && len !== index) {
      const element = item.charAt(index)
      allowed.indexOf(element) === -1 && (flag = false)
      index++
    }
    return flag
  }).length
}

console.log(countConsistentStrings('ab', ['ad', 'bd', 'aaab', 'baa', 'badab']))
